package core.september.cloudbadge.vcard.badgemodel.fields;

import javax.persistence.Embeddable;

import ezvcard.types.GenderType;
import ezvcard.types.NicknameType;
import ezvcard.types.StructuredNameType;


public class NameField extends AbsField {

	
	private StructuredNameType structuredNameType;

	private GenderType genderType;
	private String formattedName;
	private String nickName;
	//private String titl
	
	public StructuredNameType getStructuredNameType() {
		if(structuredNameType == null) {
			setStructuredNameType(new StructuredNameType());
		}
		return structuredNameType;
	}
	private void setStructuredNameType(StructuredNameType stricturedNameType) {
		this.structuredNameType = stricturedNameType;
	}
	public String getFamilyName() {
		return getStructuredNameType().getFamily();
	}
	public void setFamilyName(String familyName) {
		getStructuredNameType().setFamily(familyName);
	}
	public String getGivenName() {
		return getStructuredNameType().getGiven();
	}
	public void setGivenName(String givenName) {
		getStructuredNameType().setGiven(givenName);
	}
	public String getPrefix() {
		String pref = "";
		for(String prefix: getStructuredNameType().getPrefixes()) {
			pref+=prefix+" ";
		}
		return pref;
		
	}
	public void setPrefix(String prefix) {
		getStructuredNameType().addPrefix(prefix);
	}
	
	
	
	
	public GenderType getGenderType() {
		return getVcard().getGender();
	}
	public void setGenderType(GenderType genderType) {
		getVcard().setGender(genderType);
	}
	public String getFormattedName() {
		return getVcard().getFormattedName().getValue();
	}
	public void setFormattedName(String formattedName) {
		getVcard().setFormattedName(formattedName);
	}
	public String getNickName() {
		String nicks = "";
		for(NicknameType nick: getVcard().getNicknames()){
			for(String nickValue: nick.getValues()) {
				nicks+= nickValue+" ";
			}
		}
		return nicks;
	}
	public void setNickName(String nickName) {
		getVcard().setNickname(nickName);
	}
	@Override
	public void commit() {
		getVcard().setStructuredName(getStructuredNameType());
		
	}
	
	
}
